package seGobangClient.uiSystem3D;


import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import seGobangClient.Options;
import seGobangClient.Rule;
import seGobangResources.PathRes;

/**
 *
 * @author Leo
 */
public class OptionScene
{

    private JButton done;
    private JButton quit;
    private Font font;
    private Font font2;
    private JLabel musicLabel;
    private JLabel soundLabel;
    private JLabel ruleLabel;
    private JLabel timeLabel;
    private JLabel regretLabel;
    private JLabel GraphicLabel;
    private JLabel resetTip;
    private JLabel title;
    private JSlider setMusic;
    private JSlider setSound;
    private JComboBox setRule;
    private JComboBox setTime;
    private JComboBox setRegret;
    private JComboBox setGraphic;
    private PathRes path = new PathRes();
    private getpane Pane;

    
    public void initOptionUI(final JFrame container, final getpane mainPane, boolean FLAG_FOR_3DSCENE)
    {
        try {
            //container.setLayout(null);
            if (!FLAG_FOR_3DSCENE){
                mainPane.setLocation(0, 0);
                mainPane.setLayout(null);
                mainPane.setSize(container.getWidth(), container.getHeight());
                container.getContentPane().add(mainPane);
            
            Pane = mainPane;
            //container.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            mainPane.imgpath = path.getPath("Texture/Config/Background");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //mainPane.remove(mainPane.getComponentAt(125, 45));
        font = new Font("华文行楷", Font.PLAIN, 35);
        font2 = new Font("华文行楷", Font.PLAIN, 20);
        done = new JButton();
        quit = new JButton();
        try
        {
            done.setIcon(new ImageIcon(path.getPath("Texture/Config/Buttonback1")));
            quit.setIcon(new ImageIcon(path.getPath("Texture/Config/Buttonback2")));
        } catch (Exception e)
        {

        }
        done.setBorder(null);
        done.setCursor(new Cursor(Cursor.HAND_CURSOR));
        done.setSize(100, 30);
        done.setLocation(410, 385);
        quit.setBorder(null);
        quit.setCursor(new Cursor(Cursor.HAND_CURSOR));
        quit.setSize(100, 30);
        quit.setLocation(510, 385);
        mainPane.add(done);
        mainPane.add(quit);
        musicLabel = new JLabel("音乐");
        soundLabel = new JLabel("音效");
        ruleLabel = new JLabel("规则");
        timeLabel = new JLabel("时间限制");
        regretLabel = new JLabel("悔棋次数");
        GraphicLabel = new JLabel("游戏模式");
        resetTip = new JLabel("(更换模式重启游戏后生效)");
        title = new JLabel("选项设置");
        title.setForeground(Color.white);
        musicLabel.setForeground(Color.white);
        soundLabel.setForeground(Color.white);
        ruleLabel.setForeground(Color.white);
        timeLabel.setForeground(Color.white);
        regretLabel.setForeground(Color.white);
        GraphicLabel.setForeground(Color.white);
        resetTip.setForeground(Color.white);
        setMusic = new JSlider();
        setSound = new JSlider();
        setRule = new JComboBox();
        setTime = new JComboBox();
        setRegret = new JComboBox();
        setGraphic = new JComboBox();
        setMusic.setSize(100, 25);
        setMusic.setMinimum(0);
        setMusic.setMaximum(100);


        setMusic.setLocation(150, 102);
        setSound.setSize(100, 25);
        setSound.setMinimum(0);
        setSound.setMaximum(100);
        setSound.setLocation(150, 182);
        setGraphic.setSize(100, 25);
        setGraphic.addItem("2D模式");
        setGraphic.addItem("3D模式");
        setGraphic.setLocation(480, 262);
        setGraphic.setFont(font2);
        setRule.setSize(100, 25);
        setRule.addItem("有禁手");
        setRule.addItem("无禁手");
        setRule.setLocation(150, 262);
        setRule.setFont(font2);
        setTime.setSize(100, 25);
        setTime.addItem("5分钟");
        setTime.addItem("10分钟");
        setTime.addItem("15分钟");
        setTime.addItem("不限时");
        setTime.setLocation(480, 102);
        setTime.setFont(font2);
        setRegret.setSize(100, 25);
        setRegret.addItem("0次");
        setRegret.addItem("1次");
        setRegret.addItem("3次");
        setRegret.addItem("5次");
        setRegret.addItem("不限");
        setRegret.setLocation(480, 182);
        setRegret.setFont(font2);
        title.setSize(140, 30);
        title.setFont(font);
        title.setLocation(25, 15);
        musicLabel.setSize(70, 30);
        soundLabel.setFont(font);
        musicLabel.setFont(font);
        soundLabel.setSize(70, 30);
        musicLabel.setLocation(60, 100);
        soundLabel.setLocation(60, 180);
        GraphicLabel.setSize(140, 30);
        GraphicLabel.setLocation(320, 260);
        GraphicLabel.setFont(font);
        resetTip.setSize(250, 20);
        resetTip.setFont(font2);
        resetTip.setLocation(320, 290);
        ruleLabel.setSize(70, 30);
        ruleLabel.setFont(font);
        ruleLabel.setLocation(60, 260);
        timeLabel.setSize(140, 30);
        timeLabel.setFont(font);
        timeLabel.setLocation(320, 100);
        regretLabel.setSize(140, 30);
        regretLabel.setFont(font);
        regretLabel.setLocation(320, 180);
        mainPane.add(title);
        mainPane.add(musicLabel);
        mainPane.add(soundLabel);
        mainPane.add(ruleLabel);
        mainPane.add(timeLabel);
        mainPane.add(regretLabel);
        mainPane.add(GraphicLabel);
        mainPane.add(resetTip);
        mainPane.add(setMusic);
        mainPane.add(setSound);
        mainPane.add(setRule);
        mainPane.add(setTime);
        mainPane.add(setRegret);
        mainPane.add(setGraphic);
        done.addActionListener(new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                SceneManager.MyCurrentController.doEvent("CommitOption", null);
            }
        });
        quit.addActionListener(new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {

                SceneManager.MyCurrentController.doEvent("CancelOption", null);
            }
        });
        container.repaint();
    }

    public void clear()
    {
        try
        {
            Pane.remove(setMusic);
            setMusic = null;
            Pane.remove(setSound);
            setSound = null;
            Pane.remove(musicLabel);
            musicLabel = null;
            Pane.remove(soundLabel);
            soundLabel = null;
            Pane.remove(setRule);
            setRule = null;
            Pane.remove(ruleLabel);
            ruleLabel = null;
            Pane.remove(setTime);
            setTime = null;
            Pane.remove(timeLabel);
            timeLabel = null;
            Pane.remove(setRegret);
            setRegret = null;
            Pane.remove(regretLabel);
            regretLabel = null;
            Pane.remove(done);
            done = null;
            Pane.remove(quit);
            quit = null;
            Pane.remove(setGraphic);
            setGraphic = null;
            Pane.remove(GraphicLabel);
            GraphicLabel = null;
            Pane.remove(resetTip);
            resetTip = null;
            //mainPane.remove(option);
            Pane.remove(Pane.getComponentAt(535, 0));
        } catch (Exception e)
        {

        }
    }

    public int getGraphic_Message()
    {
        return setGraphic.getSelectedIndex();
    }

    public int getMusicVolum_Message()
    {
        return setMusic.getValue();
    }

    public int getSFXVolum_Message()
    {
        return setSound.getValue();
    }

    public int getTimeLimit_Message()
    {
        if (setTime.getSelectedIndex() == 0)
        {
            return 300;
        } else if (setTime.getSelectedIndex() == 1)
        {
            return 600;
        } else if (setTime.getSelectedIndex() == 2)
        {
            return 900;
        } else if (setTime.getSelectedIndex() == 3)
        {
            return -1;
        } else
        {
            return -1;
        }
    }

    public int getRegretTimes_Message()
    {
        if (setRegret.getSelectedIndex() == 0)
        {
            return 0;
        } else if (setRegret.getSelectedIndex() == 1)
        {
            return 1;
        } else if (setRegret.getSelectedIndex() == 2)
        {
            return 3;
        } else if (setRegret.getSelectedIndex() == 3)
        {
            return 5;
        } else if (setRegret.getSelectedIndex() == 4)
        {
            return -1;
        } else
        {
            return -1;
        }
    }

    public boolean getforbids_Message()
    {
        if (setRule.getSelectedIndex() == 0)
        {
            return true;
        } else
        {
            return false;
        }
    }

    public void Options_perform(Options op)
    {
        setMusic.setValue(op.MusicVolum);
        setSound.setValue(op.SFXVolum);
        setGraphic.setSelectedIndex(op.GraphicMode);
    }

    public void Rule_perform(Rule rl)
    {
        if (rl.TimeLimit == 300)
        {
            setTime.setSelectedIndex(0);
        } else if (rl.TimeLimit == 600)
        {
            setTime.setSelectedIndex(1);
        } else if (rl.TimeLimit == 900)
        {
            setTime.setSelectedIndex(2);
        } else if (rl.TimeLimit == -1)
        {
            setTime.setSelectedIndex(3);
        } else
        {
            setTime.setSelectedIndex(3);
        }

        if (rl.RegretTimes == 0)
        {
            setRegret.setSelectedIndex(0);
        } else if (rl.RegretTimes == 1)
        {
            setRegret.setSelectedIndex(1);
        } else if (rl.RegretTimes == 3)
        {
            setRegret.setSelectedIndex(2);
        } else if (rl.RegretTimes == 5)
        {
            setRegret.setSelectedIndex(3);
        } else if (rl.RegretTimes == -1)
        {
            setRegret.setSelectedIndex(4);
        }

        if (rl.forbids)
        {
            setRule.setSelectedIndex(0);
        } else
        {
            setRule.setSelectedIndex(1);
        }
    }
}